package org.supda.system.controller.monitor;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.WebRequest;
import org.supda.system.controller.common.BaseController;
import org.supda.system.entity.TMessage;
import org.supda.system.entity.TServerWarnProperties;
import org.supda.system.entity.TUser;
import org.supda.system.service.TMessageService;
import org.supda.system.service.TServerWarnPropertiesService;
import org.supda.system.util.DataTablePageUtil;

/**
 * 告警信息控制器
 * @author supda
 * @Date 2017-2-24 下午3:39:16
 *
 */
@Controller
@RequestMapping("/warn")
public class WarnController  extends BaseController{

	@Inject private TServerWarnPropertiesService serverWarnPropertiesService;
	
	@Inject private TMessageService tMessageService;
	
	/**
	 * 告警列表UI
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = {"/",""}, method=RequestMethod.GET, produces="text/html;charset=utf-8")
	public String warnUI(HttpServletRequest request, Model model){
		//查询出子菜单的所有操作
		model.addAttribute("menuId",getOID());
		return SYSTEM_MONITOR_VIEW_PACKAGE+"warn/warn";
	}
	
	/**
	 * 告警查询
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/search", method=RequestMethod.POST, produces="text/html;charset=utf-8")
    public @ResponseBody DataTablePageUtil<TMessage> search(WebRequest request){  
    	DataTablePageUtil<TMessage> dtp = new DataTablePageUtil<TMessage>(request); 
    	tMessageService.listByDataTable(dtp);
    	return dtp; 
    }
	
	
//		查看 GET:/monitor/warn_show.shtml
	@RequestMapping(value = "/show", method=RequestMethod.GET, produces="text/html;charset=utf-8")
	public String show(HttpServletRequest request, Long id , Model model){
		
		TServerWarnProperties tsw = serverWarnPropertiesService.show(id);
		
		model.addAttribute("tsw", tsw);
		
		return SYSTEM_MONITOR_VIEW_PACKAGE+"warn/warn-show";
	}
}
